package com.skycode7.servlet;

import com.skycode7.dao.NewsDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@WebServlet ("/newsDel.jsp")
public class NewsDelServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        String newsId = req.getParameter("NewsId");
        int result = (new NewsDao()).delete(Integer.parseInt(newsId));
        if (result > 0) {
            //补充知识 跳转到网页news。html中
            resp.sendRedirect("news.html");
        }else {
            req.getRequestDispatcher("WEB-INF/error.jsp").forward(req, resp);
        }
    }
}
